// 切片类型
import {createSlice, PayloadAction} from "@reduxjs/toolkit";
import { InfoType } from "../util/publicType";
import {RootState} from "./index";

// 切片初始化
const initInfo: InfoType = {
    id: "",
    jurisdictions: [],
    created_at: 0,
    lasted_at: 0,
    username: ""
}

// 个人信息切片
export const infoSlice = createSlice({
    // 切片标识
    name: "info",
    // 初始值
    initialState: initInfo,
    // 定义动作
    reducers: {
        // 更新
        updateInfo: (state: InfoType, action: PayloadAction<InfoType>) => {
            return state = action.payload;
        }
    }
});

// 获取动作并导出
export const {updateInfo} = infoSlice.actions;
// 获取状态，并导出
export const selectInfo = (state: RootState) => state.info;

// 导出更新操作
export default infoSlice.reducer